﻿@{
    ViewBag.Title = "自动货机首页";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@Styles.Render("~/Content/css/home")
<input id="homeType" type="hidden" value="@ViewBag.Type" />
<section id="preHome" class="OpenLayout" style="display:none"></section>
<section id="home" style="display:none"></section>
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp"></script>
<script>
    window.onload = function () {
        UserInfoMgr.setOpenId('@ViewBag.OpenId', function (openId) {
            if (openId == null || openId == "") {
                venderDialog("获取用户信息失败，请关闭浏览器稍后重试。");
            } else {
                UserInfoMgr.weixinLogin(null, null);
            }
        });
        var homeType = $("#homeType").val();
        if (homeType == 1) {
            showHome();
        } else {
            wxJSSDK();
            showPreHome();
        }
    }

    function showPreHome() {
        var url = '/Home/PreHome';
        NativeAjax(null, url, function (msg) {
            loadPartialViewResult(msg, $("#preHome"), 1);
        });
    }

    function showHome() {
        var url = '/Home/Home';
        window.location.href = url;
        //NativeAjax(null, url, function (msg) {
        //    loadPartialViewResult(msg, $("#home"), 1);
        //});
    }

    function wxJSSDK() {
        wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: '@ViewData["AppId"]', // 必填，公众号的唯一标识
            timestamp: '@ViewData["Timestamp"]', // 必填，生成签名的时间戳
            nonceStr: '@ViewData["NonceStr"]', // 必填，生成签名的随机串
            signature: '@ViewData["Signature"]',// 必填，签名
            jsApiList: [
                  "checkJsApi",
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareWeibo',
                    'hideMenuItems',
                    'showMenuItems',
                    'hideAllNonBaseMenuItem',
                    'showAllNonBaseMenuItem',
                    'translateVoice',
                    'startRecord',
                    'stopRecord',
                    'onRecordEnd',
                    'playVoice',
                    'pauseVoice',
                    'stopVoice',
                    'uploadVoice',
                    'downloadVoice',
                    'chooseImage',
                    'previewImage',
                    'uploadImage',
                    'downloadImage',
                    'getNetworkType',
                    'openLocation',
                    'getLocation',
                    'hideOptionMenu',
                    'showOptionMenu',
                    'closeWindow',
                    'scanQRCode',
                    'chooseWXPay',
                    'openProductSpecificView',
                    'addCard',
                    'chooseCard',
                    'openCard'
            ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2。详见：http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
        });

        wx.error(function (res) {
            venderDialog("获取地址信息失败，请重新进入网页！");
        });

        wx.ready(function () {
            wx.getLocation({
                type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
                success: function (res) {
                    var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                    var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                    var speed = res.speed; // 速度，以米/每秒计
                    var accuracy = res.accuracy; // 位置精度
                    AddressMgr.setWXAddr("", "", latitude, longitude);
                }
            });
        });
    }
</script>